<template>
  <!-- 基于 Element UI 新增和修改弹窗 -->
    <a-drawer
            :title="!dataForm.id ? '添加' : '审核'"
            :visible="visible"
            @close="cancel"
            :body-style="{ paddingBottom: '80px' }"
            :width="750"
    >
    <!-- 新增和创建表单表单 -->
    <el-form :model="dataForm" :rules="dataRule"  v-loading="loading" ref="dataForm" @keyup.enter.native="dataSubmit()" label-width="80px" style="padding: 0px 10px;margin: 0px 10px">
    <el-form-item label="用户ID" >
      <el-input v-model="dataForm.userid" placeholder="请输入用户ID" size="small" disabled></el-input>
    </el-form-item>
    <el-form-item label="姓名" >
      <el-input v-model="dataForm.name" placeholder="请输入姓名" size="small" disabled></el-input>
    </el-form-item>
    <el-form-item label="账户" >
      <el-input v-model="dataForm.account" placeholder="请输入账户" size="small" disabled></el-input>
    </el-form-item>

    <el-form-item label="提现金额" >
      <el-input v-model="dataForm.amount/100.0" placeholder="请输入提现金额" size="small" disabled></el-input>
    </el-form-item>
    <el-form-item label="审核状态" >
      <el-select v-model="dataForm.status" placeholder="请选择审核状态" class="width100" filterable clearable>
        <el-option
          v-for="item in selOptions.wlStatus"
          :key="item.value"
          :value="item.value"
          :label="item.label">
        </el-option>
      </el-select>

    </el-form-item>

    </el-form>
        <div :style="{position: 'absolute',right: 0,bottom: 0,width: '100%', borderTop: '1px solid #e9e9e9',padding: '10px 16px',background: '#fff',textAlign: 'right',zIndex: 1,}">
            <el-button @click="cancel()" :style="{ marginRight: '8px' }">取消</el-button>
            <el-button type="primary" @click="submit()">确定</el-button>
        </div>
  </a-drawer>
</template>

<script>
    import api from '@/api/api'
    export default {
    components: {
    },
    data () {
      return {
        visible: false,
        selOptions: {},
        loading:false,
        dataForm: {
          id: 0,
          userid: '' ,
          name: '' ,
          account: '' ,
          info: '' ,
          type: '' ,
          amount: '' ,
          status: '' ,
          createtime: '' ,
          updatetime: ''
        },
        dataRule: {
          userid: [
            { required: true, message: '用户ID  为必填项', trigger: 'blur' }
          ],
          name: [
            { required: true, message: '姓名  为必填项', trigger: 'blur' }
          ],
          account: [
            { required: true, message: '账户  为必填项', trigger: 'blur' }
          ],
          info: [
            { required: true, message: '信息  为必填项', trigger: 'blur' }
          ],
          type: [
            { required: true, message: '类型：0，支付宝，1银行卡  为必填项', trigger: 'blur' }
          ],
          amount: [
            { required: true, message: '提现金额  为必填项', trigger: 'blur' }
          ],
          status: [
            { required: true, message: '状态：0待审核，1审核通过，2已打款，3拒绝  为必填项', trigger: 'blur' }
          ],
          createtime: [
            { required: true, message: '创建时间  为必填项', trigger: 'blur' }
          ],
          updatetime: [
            { required: true, message: '更新时间  为必填项', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) { // 初始化表单验证规则
        this.dataForm.id = id || undefined
        this.visible = true
        this.selOptions=this.$constants.selOptions;
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.id){
              this.loading = true
                api.post('rest/vabc/withdrawlog/info',{id:this.dataForm.id}).then(res => {
                this.dataForm = res;
            }).finally(() => {
                this.loading = false
            });
          }
        })
      },
      // 表单数据提交
      submit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.loading = true
            let postData=Object.assign({},this.dataForm)
            if (!this.dataForm.id){
                postData.id==undefined
                api.post('rest/vabc/withdrawlog/save',postData).then(res =>{
                    this.$message.success("创建成功")
                    this.reset()
                    this.visible = false
                    this.$parent.getDataList()
                }).finally(() => {
                    this.loading = false
                });
            }else{

              if(postData.status!==1){
                this.doUpdate(postData)
              }else {
                this.$confirm(`审核成功后会立即打款，打款后无法撤销，确定进行吗`, '提示', {
                  confirmButtonText: '立即打款',
                  cancelButtonText: '取消',
                  type: 'warning'
                }).then(() => {
                  this.doUpdate(postData)
                })
              }
            }
          }
        })
      },
      doUpdate(postData){
        api.post('rest/vabc/withdrawlog/update', postData).then(res => {
          this.$message.success('操作成功')
          this.reset()
          this.visible = false
          this.$parent.getDataList()
        }).finally(() => {
          this.loading = false
        })
      },
     cancel(){
        this.visible = false
        this.reset()
    },
    reset(){
        this.$refs.dataForm.resetFields()
        this.$data.dataForm=JSON.parse(JSON.stringify(this.$options.data().dataForm))
        //图片回写
        //this.$refs["childData"].fileList=[]
    }
    }
  }
</script>
